<?php 
/**
 *
 *
 */
include_once('User.php');
include_once('db_connect.php');

class Picture {

	private $ID;
	private $userID;
	private $link;
	private $desciption;
	private $destroy;

	function Picture() {
		$this->userID = 0;
		$this->link = "";
		$this->desciption = "";
		$this->destroy = 0;
	}

	function connect() {
		$this->connect = new Connect();
		$this->mysqli = $this->connect->getMysqli();
	}

	function getID() {
		return $this->ID;
	}

	function setID($value) {
		$this->ID = $value;
	}

	function getUserID() {
		return $this->userID;
	}

	function setUserID($value) {
		$this->userID = $value;
	}

	function getLink() {
		return $this->link;
	}

	function setLink($value) {
		$this->link = $value;
	}

	function getDescription() {
		return $this->desciption;
	}

	function setDescription($value) {
		$this->desciption = $value;
	}

	function getDestroy() {
		return $this->destroy;
	}

	function setDestroy($value) {
		$this->destroy = $value;
	}

	/**
	 *	Function get pictures of user
	 *	- input: $userID
	 *	- output: pictures list
	 *
	 */
	function getPicturesList($userID) {

		$this->connect();

		$sql = "SELECT Link, Description FROM PICTURE WHERE UserID = ?";
		// Prepare statement
		$prSelect = $this->mysqli->prepare($sql);

		if($prSelect) {

		} else {
			echo "Prepare failed: (" .$this->mysqli->errno. ") " .$this->mysqli->error;
		}

		//Execute
		if ($prSelect->execute()) {

		} else {
			echo "Execute Failed: (" .$prSelect->errno. ") " .$prSelect->error;
		}

		$pictures[];
		$i = 0;

		while() {
			$picture = new Picture();

			$picture->setLink( );
			$picture->setDescription( );

			$pictures[$i] = $picture;
			$i++;
		}

		return $pictures;
	}

	function Insert($picture) {

		$this->connect();

		$sql = "INSERT INTO PICTURE 
				(UserID, Link, Description, Destroy) 
				VALUES 
				(?, ?, ?, ?)";

		$prInsert = $this->mysqli->prepare($sql);

		if($prInsert) {
			//Bind
			$prInsert->bind_param('issi', 
									$picture->getUserID(),
									$picture->getLink(),
									$pictuire->getDescription(),
									$picture->getDestroy()
								);
		} else {
			echo "Prepare failed: (" .$this->mysqli->errno. ") " .$this->mysqli->error;
		}

		//Execute
		if ($prSelect->execute()) {
			//Execute successfull
		} else {
			echo "Execute Failed: (" .$prSelect->errno. ") " .$prSelect->error;
		}
	}

	function Update($picture) {

		$this->connect();

		$sql = "UPDATE PICTURE SET
				Link = ?,
				Description = ?,
				Destroy = ?
				WHERE
				UserID = ?";

		$prInsert = $this->mysqli->prepare($sql);

		if($prInsert) {
			//Bind
			$prInsert->bind_param('issi', 
									$picture->getLink(),
									$pictuire->getDescription(),
									$picture->getDestroy(),
									$picture->getUserID()
								);
		} else {
			echo "Prepare failed: (" .$this->mysqli->errno. ") " .$this->mysqli->error;
		}

		//Execute
		if ($prSelect->execute()) {
			//Execute successfull
		} else {
			echo "Execute Failed: (" .$prSelect->errno. ") " .$prSelect->error;
		}
	}
}
?>
